package com.bluesky.light2.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.bluesky.light2.model.Category;
import com.bluesky.light2.service.CategoryService;
import com.opensymphony.xwork2.ActionSupport;

@Component("categoryAction")
@Scope("prototype")
public class CategoryAction extends ActionSupport {
	
	private Category category;
	private CategoryService categoryService;
	private List<Category> categories;
	
	public List<Category> getCategories() {
		return categories;
	}

	public void setCategories(List<Category> categories) {
		this.categories = categories;
	}

	public String addInput() {
		return INPUT;
	}

	public Category getCategory() {
		return category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}
	
	public String add() {
		categoryService.add(category);
		return SUCCESS;
	}
	
	public String list() {
		categories = categoryService.getCategories();
//System.out.println("-----------------------------------------" + categories);
		return SUCCESS;
	}

	public CategoryService getCategoryService() {
		return categoryService;
	}

	@Resource
	public void setCategoryService(CategoryService categoryService) {
		this.categoryService = categoryService;
	}
}
